// import {Slider, sliderHide, sliderShow} from "../lib/kslider";
// new Slider({content: text字符串})

const $ = require('../lib/kdom');
function Slider(opts, cb) {
  let params = {
    box: 'body',//盒子
    id: 'sidebarbox',
    content: '',//文本字符串
  };
  opts = opts || {};
  for (let k in params) {
    if (opts[k] !== undefined) params[k] = opts[k];
  }
  params.box = $.qu(params.box);

  function init() {
    const that = this;
    let txt = params.content;
    if ($.id(params.id)) {
      if (sidebarContent) sidebarContent.innerHTML = txt;
    } else {
      const dv = document.createElement('div');
      dv.className = 'sidebarbox';
      dv.id = params.id;
      dv.innerHTML = `<div class="sidebar-content" id="sidebarContent">${txt}</div>`;
      params.box.appendChild(dv);
    }
    if (cb) {
      cb();
    }
  }

  init();
}

function sliderHide() {
  $.removeClass(sidebarbox, 'active');
  setTimeout(function() {
    $.removeClass(sidebarbox, 'on');
  }, 150);
  // obj.onclick = function () {
  //   $.removeClass(sidebarbox, 'active');
  // }
}

function sliderShow() {
  $.addClass(sidebarbox, 'on');
  setTimeout(function() {
    $.addClass(sidebarbox, 'active');
  });
  // obj.onclick = function () {
  //   $.addClass(sidebarbox, 'active');
  // }
}
export {Slider, sliderHide, sliderShow};